package thread;

import static java.lang.String.join;

/**
 * @Author: Miyako
 * @Date: 2024-07-24-8:47
 * @Description: join()方法实现线程顺序切换
 */
public class ThreadTOJoin {
    public static void main(String[] args) {
        Thread t1, t2, t3;

        t1 = new Thread(() -> {
            System.out.println("t1");
        });
        t2 = new Thread(() -> {
            try {
                t1.join();//t1线程执行完再执行t2
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t2");
        });

        t3 = new Thread(() -> {
            try {
                t2.join(100, 1000);//t2线程执行完再执行t3,最多等待100毫秒+1000纳秒
                System.out.println("t2");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t3");
        });
        t1.start();
        t2.start();
        t3.start();
        //完成顺序切换
    }
}
